// eslint-disable-next-line
const fs = require('fs')
// eslint-disable-next-line
const path = require('path')

const filePath = './install.sh'
const versionIncrease = 1

fs.readFile(path.join(__dirname, filePath), 'utf8', function (err, data) {
  if (err) {
    return console.log('读取文件失败！' + err.message)
  }
  let newVersion
  const updatedData = data.replace(/(image_version="v\d+\.\d+\.)(\d+)"/, (match, prefix, currentVersion) => {
    console.log('当前版本为', currentVersion)
    newVersion = parseFloat(currentVersion) + versionIncrease
    return `${prefix}${newVersion}"`
  })

  fs.writeFile(filePath, updatedData, 'utf8', err => {
    if (err) {
      console.error(err)
      return
    }
    console.log(`修改版本成功为${newVersion}`)
  })
})
